package com.xiaoyu.lanling.widget.picker.area;

import com.xiaoyu.base.utils.ListUtil;

import java.util.ArrayList;
import java.util.List;

public class PickerAreaModel {

    public final boolean isInvalid;
    public final List<String> provinceNameList;
    public final List<List<String>> cityNameList;
    public final List<List<List<String>>> countyNameList;

    public PickerAreaModel(List<PickerProvinceModel> provinceModelList) {
        this.provinceNameList = new ArrayList<>(provinceModelList.size());
        this.cityNameList = new ArrayList<>();
        this.countyNameList = new ArrayList<>();

        for (PickerProvinceModel pickerModel : provinceModelList) {
            provinceNameList.add(pickerModel.province);
            cityNameList.add(pickerModel.cityList);
            countyNameList.add(pickerModel.countyList);
        }

        isInvalid = isPickerListNullOrEmpty();
    }

    private boolean isPickerListNullOrEmpty() {
        if (ListUtil.isNullOrEmpty(provinceNameList) || ListUtil.isNullOrEmpty(cityNameList) || ListUtil.isNullOrEmpty(countyNameList)) {
            return true;
        }
        for (List<String> cityList : cityNameList) {
            if (ListUtil.isNullOrEmpty(cityList)) {
                return true;
            }
        }

        for (List<List<String>> superiorList : countyNameList) {
            if (ListUtil.isNullOrEmpty(superiorList)) {
                return true;
            }

            for (List<String> countyList : superiorList) {
                if (ListUtil.isNullOrEmpty(countyList)) {
                    return true;
                }
            }
        }
        return false;
    }
}
